package com.flying.invest.invest.model;

import java.util.Date;

import com.flying.common.util.Codes;
import com.flying.framework.annotation.ConstantEnum;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.ServiceField;
import com.flying.framework.annotation.ServiceFieldParam;
import com.flying.framework.data.Data;
import com.flying.framework.data.DataSerializable;
import com.flying.framework.metadata.Meta;
import com.flying.invest.account.model.Account;
import com.flying.invest.assets.model.Assets;
import com.flying.invest.survey.model.Survey;

@SuppressWarnings("serial")
@Meta(id="i_investment",title="投资项目", table="i_investment", primaryKeys={"invest_id"})
public class Investment extends Data implements DataSerializable {
	public final static String ENTITY_NAME = "i_investment";
	
	public final static String INVEST_ID = "invest_id";
	public final static String ASSETS_ID = "assets_id";
	public final static String USER_ID = "user_id";
	public final static String ACCOUNT_ID = "account_id";
	public final static String SURVEY_ID = "survey_id";
	public final static String SURVEY_STATUS = "survey_status";
	public final static String CURRENCY = "currency";
	public final static String STATUS = "status";
	public final static String PLAN_START = "plan_start";
	public final static String PLAN_END = "plan_end";
	public final static String PLAN_MONEY = "plan_money";
	public final static String LIMIT_RATE = "limit_rate";
	public final static String ACTUAL_START = "actual_start";
	public final static String ACTUAL_END = "actual_end";
	public final static String ACTUAL_MONEY = "actual_money";
	public final static String TAX_RATE = "tax_rate";
	public final static String TAX = "tax";
	public final static String QUANTITY = "quantity";
	public final static String COST = "cost";
	public final static String COST_PRICE = "cost_price";
	public final static String AMOUNT = "amount";
	public final static String PRICE = "price";
	public final static String MAX_PROFIT = "max_profit";
	public final static String MIN_PROFIT = "min_profit";
	public final static String FELL_PROFIT = "fell_profit";
	public final static String MAX_PRICE = "max_price";
	public final static String MIN_PRICE = "min_price";
	public final static String CODE = "code";
	public final static String NAME = "name";
	public final static String REMARKS = "remarks";
	public final static String INCLUDE_STRATEGIES = "include_strategies";
	//
	public final static String MARKET_INFO = "market_info";
	public final static String ASSETS_INFO = "assets_info";
	public final static String BUY_INFO = "buy_info";
	public final static String SELL_INFO = "sell_info";
	//
	public final static String CREATOR = "creator";
	public final static String CREATE_TIME = "create_time";
	public final static String UPDATOR = "updator";
	public final static String UPDATE_TIME = "update_time";
	
	public enum Status implements ConstantEnum<Integer> {
		PREPARING(0, "准备中"), HOUSING(1, "建仓中"), INVESTING(2, "投资中"), FINISHED(9, "已结束");

		public final int value;
		public final String remarks;

		Status(int value, String remarks) {
			this.value = value;
			this.remarks = remarks;
		}
		
		@Override
		public Integer value() {
			return this.value;
		}

		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum SurveyStatus implements ConstantEnum<Integer> {
		NONE(0, "未设置"), CREATED(1, "已准备"), SURVEIED(2, "已完成");

		public final int value;
		public final String remarks;

		SurveyStatus(int value, String remarks) {
			this.value = value;
			this.remarks = remarks;
		}
		
		@Override
		public Integer value() {
			return this.value;
		}

		@Override
		public String text() {
			return remarks;
		}
	}
	
	
	@Param(value=INVEST_ID,   required=true,   desc="ID" , generator=Codes.AUTO_INCREMENT)
	private Long investId;
	
	@Param(value=ASSETS_ID,   required=true,   desc="投资品种" )
	private Long assetsId;
	
	@Param(value=USER_ID,   required=true,   desc="所属用户" )
	private Long userId;
	
	@Param(value=ACCOUNT_ID,   required=true,   desc="账户ID" )
	private Long accountId;
	
	@Param(value=SURVEY_ID,   required=false,   desc="调查ID" )
	private Long surveyId;
	
	@Param(value=SURVEY_STATUS,   required=false,   maxlength=0, enumClass=SurveyStatus.class,	desc="问卷状态" )
	private Integer surveyStatus;
	
	@Param(value=CURRENCY,   required=false,   maxlength=10,	desc="币种" )
	private String currency;
	
	@Param(value=STATUS,   required=false,   maxlength=0, enumClass=Status.class,	desc="状态" )
	private Integer status;
	
	@Param(value=PLAN_START,   required=false,   desc="计划开始" )
	private Date planStart;
	
	@Param(value=PLAN_END,   required=false,   desc="计划结束" )
	private Date planEnd;
	
	@Param(value=PLAN_MONEY,   required=false,   desc="计划投入金额" )
	private Double planMoney;
	
	@Param(value=LIMIT_RATE,   required=false,   desc="限制比例" )
	private Double limitRate;
	
	@Param(value=TAX_RATE,   required=false,   desc="交易税率" )
	private Double taxRate;
	
	@Param(value=ACTUAL_START,   required=false,   desc="实际开始" )
	private Date actualStart;
	
	@Param(value=ACTUAL_END,   required=false,   desc="实际结束" )
	private Date actualEnd;
	
	@Param(value=ACTUAL_MONEY,   required=false,   desc="实际投入金额" )
	private Double actualMoney;
	
	@Param(value=TAX,   required=false,   desc="税额" )
	private Double tax;
	
	@Param(value=QUANTITY,   required=false,   desc="资产数量" )
	private Double quantity;
	
	@Param(value=COST,   required=false,   desc="成本" )
	private Double cost;
	
	@Param(value=COST_PRICE,   required=false,   desc="成本价" )
	private Double costPrice;
	
	@Param(value=AMOUNT,   required=false,   desc="市值" )
	private Double amount;
	
	@Param(value=PRICE,   required=false,   desc="价格" )
	private Double price;
	//
	@Param(value=MAX_PROFIT,   required=false,   desc="最大利润" )
	private Double maxProfit;

	@Param(value=MIN_PROFIT,   required=false,   desc="最小利润" )
	private Double minProfit;

	@Param(value=FELL_PROFIT,   required=false,   desc="回落最小利润" )
	private Double fellProfit;

	@Param(value=MAX_PRICE,   required=false,   desc="最高价格" )
	private Double maxPrice;

	@Param(value=MIN_PRICE,   required=false,   desc="最低价格" )
	private Double minPrice;
	//
	@Param(value=CODE,   required=true,   maxlength=3,	desc="代码" )
	private String code;
	
	@Param(value=NAME,   required=true,   maxlength=50,	desc="名称" )
	private String name;
	
	@Param(value=REMARKS,   required=false,   maxlength=400,	desc="说明" )
	private String remarks;

	@Param(value=INCLUDE_STRATEGIES,   required=false,   maxlength=400,	desc="包含策略" )
	private String includeStrategies;
	//
	@Param(value=MARKET_INFO,   required=false,   maxlength=400,	desc="大盘判断" )
	private String marketInfo;

	@Param(value=ASSETS_INFO,   required=false,   maxlength=400,	desc="入市时机" )
	private String assetsInfo;
	
	@Param(value=BUY_INFO,   required=false,   maxlength=400,	desc="建仓计划" )
	private String buyInfo;
	
	@Param(value=SELL_INFO,   required=false,   maxlength=400,	desc="出仓标准" )
	private String sellInfo;
	//
	@Param(value=CREATOR,   required=false,   maxlength=40,	desc="创建人" )
	private String creator;
	
	@Param(value=CREATE_TIME,   required=false,   desc="创建时间" )
	private Date createTime;
	
	@Param(value=UPDATOR,   required=false,   maxlength=40,	desc="修改人" )
	private String updator;
	
	@Param(value=UPDATE_TIME,   required=false,   desc="修改时间" )
	private Date updateTime;
	//
	@ServiceField(serviceId="AssetsService:findById2", params={@ServiceFieldParam(param=Assets.ASSETS_ID, value="$"+ASSETS_ID)})
	@Param(value="assets",   required=false,	desc="资产", ignored=true)
	private Assets assets;

	@ServiceField(serviceId="AccountService:findById", params={@ServiceFieldParam(param=Account.ACCOUNT_ID, value="$"+ACCOUNT_ID)})
	@Param(value="account",   required=false,	desc="账户", ignored=true)
	private Account account;

	@ServiceField(serviceId="SurveyService:findById", params={@ServiceFieldParam(param=Survey.SURVEY_ID, value="$"+SURVEY_ID)})
	@Param(value="survey",   required=false,	desc="账户", ignored=true)
	private Survey survey;
	
	public Long getInvestId() {
		return this.investId;
	}
	
	public void setInvestId(Long investId) {
		this.investId = investId;
	}
	
	public Long getAssetsId() {
		return this.assetsId;
	}
	
	public void setAssetsId(Long assetsId) {
		this.assetsId = assetsId;
	}
	
	public Long getUserId() {
		return this.userId;
	}
	
	public void setUserId(Long userId) {
		this.userId = userId;
	}
	
	public Long getAccountId() {
		return accountId;
	}

	public void setAccountId(Long accountId) {
		this.accountId = accountId;
	}

	public Long getSurveyId() {
		return this.surveyId;
	}
	
	public void setSurveyId(Long surveyId) {
		this.surveyId = surveyId;
	}
	
	public Integer getSurveyStatus() {
		return surveyStatus;
	}

	public void setSurveyStatus(Integer surveyStatus) {
		this.surveyStatus = surveyStatus;
	}
	
	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public Integer getStatus() {
		return this.status;
	}
	
	public void setStatus(Integer status) {
		this.status = status;
	}
	
	public Date getPlanStart() {
		return this.planStart;
	}
	
	public void setPlanStart(Date planStart) {
		this.planStart = planStart;
	}
	
	public Date getPlanEnd() {
		return this.planEnd;
	}
	
	public void setPlanEnd(Date planEnd) {
		this.planEnd = planEnd;
	}
	
	public Double getPlanMoney() {
		return this.planMoney;
	}
	
	public void setPlanMoney(Double planMoney) {
		this.planMoney = planMoney;
	}
	
	public Double getLimitRate() {
		return limitRate;
	}

	public void setLimitRate(Double limitRate) {
		this.limitRate = limitRate;
	}
	
	public Date getActualStart() {
		return this.actualStart;
	}
	
	public void setActualStart(Date actualStart) {
		this.actualStart = actualStart;
	}
	
	public Date getActualEnd() {
		return this.actualEnd;
	}
	
	public void setActualEnd(Date actualEnd) {
		this.actualEnd = actualEnd;
	}
	
	public Double getActualMoney() {
		return this.actualMoney;
	}
	
	public void setActualMoney(Double actualMoney) {
		this.actualMoney = actualMoney;
	}
	
	public Double getTax() {
		return this.tax;
	}
	
	public void setTax(Double tax) {
		this.tax = tax;
	}
	
	public Double getQuantity() {
		return this.quantity;
	}
	
	public void setQuantity(Double quantity) {
		this.quantity = quantity;
	}
	
	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Double getCost() {
		return this.cost;
	}
	
	public void setCost(Double cost) {
		this.cost = cost;
	}
	
	public Double getCostPrice() {
		return this.costPrice;
	}
	
	public void setCostPrice(Double costPrice) {
		this.costPrice = costPrice;
	}
	
	public Double getAmount() {
		return this.amount;
	}
	
	public void setAmount(Double amount) {
		this.amount = amount;
	}

	public Double getMaxProfit() {
		return maxProfit;
	}

	public void setMaxProfit(Double maxProfit) {
		this.maxProfit = maxProfit;
	}

	public Double getMinProfit() {
		return minProfit;
	}

	public void setMinProfit(Double minProfit) {
		this.minProfit = minProfit;
	}

	public Double getFellProfit() {
		return fellProfit;
	}

	public void setFellProfit(Double fellProfit) {
		this.fellProfit = fellProfit;
	}

	public Double getMaxPrice() {
		return maxPrice;
	}

	public void setMaxPrice(Double maxPrice) {
		this.maxPrice = maxPrice;
	}

	public Double getMinPrice() {
		return minPrice;
	}

	public void setMinPrice(Double minPrice) {
		this.minPrice = minPrice;
	}

	public Double getTaxRate() {
		return taxRate;
	}

	public void setTaxRate(Double taxRate) {
		this.taxRate = taxRate;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRemarks() {
		return this.remarks;
	}
	
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	
	public String getIncludeStrategies() {
		return includeStrategies;
	}

	public void setIncludeStrategies(String includeStrategies) {
		this.includeStrategies = includeStrategies;
	}

	public String getMarketInfo() {
		return marketInfo;
	}

	public void setMarketInfo(String marketInfo) {
		this.marketInfo = marketInfo;
	}

	public String getAssetsInfo() {
		return assetsInfo;
	}

	public void setAssetsInfo(String assetsInfo) {
		this.assetsInfo = assetsInfo;
	}

	public String getBuyInfo() {
		return buyInfo;
	}

	public void setBuyInfo(String buyInfo) {
		this.buyInfo = buyInfo;
	}

	public String getSellInfo() {
		return sellInfo;
	}

	public void setSellInfo(String sellInfo) {
		this.sellInfo = sellInfo;
	}

	public String getCreator() {
		return this.creator;
	}
	
	public void setCreator(String creator) {
		this.creator = creator;
	}
	
	public Date getCreateTime() {
		return this.createTime;
	}
	
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	public String getUpdator() {
		return this.updator;
	}
	
	public void setUpdator(String updator) {
		this.updator = updator;
	}
	
	public Date getUpdateTime() {
		return this.updateTime;
	}
	
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	//
	public Assets getAssets() {
		return assets;
	}

	public Account getAccount() {
		return account;
	}

	public Survey getSurvey() {
		return survey;
	}

	public String getAssetsName() {
		Assets t = this.getAssets();
		return t == null? null: t.getName();
	}
	
	public String getAccountName() {
		Account t = this.getAccount();
		return t == null? null: t.getName();
	}
	
	public String getSurveyName() {
		Survey t = this.getSurvey();
		return t == null? null: t.getName();
	}

	public Double getProfit() {
		Double amount = this.getAmount();
		Double cost = this.getCost();
		//Double tax = this.getTax();
		if(amount == null) amount = 0.0;
		if(cost == null) cost = 0.0;
		//if(tax == null) tax = 0.0;
		return amount - cost;
	}
}